package org.blackcat.web.filter;

import org.blackcat.common.StringUtils;
import org.blackcat.dao.redis.RedisHandle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by Duo Duo on 2017/1/5.
 */
@Component
public class LoginedUser {

    @Autowired
    private RedisHandle redisHandle;

    public String getToken(HttpServletRequest request){
        String token = "";
        //web端浏览器保存信息
        Cookie[] cookies = request.getCookies();
        if(cookies != null){
            for(Cookie cookie : cookies){
                if(cookie.getName().equals("token") ){
                    token = cookie.getValue();
                }
            }
        }
        //安卓作为参数上传
        if(StringUtils.isNullOrEmpty(token)){
            token = request.getParameter("token");
        }
        if(StringUtils.isNullOrEmpty(token)){
            return null;
        }
        return token;
    }

}
